package domain.user;

import java.util.Date ;

import org.compass.annotations.Searchable ;
import org.compass.annotations.SearchableProperty ;

import persistence.Persistent ;
import util.DateTools ;

/**
 * represents a member login.
 *
 * @author idan
 */
@Searchable
public class Login extends Persistent
{
	private static final long serialVersionUID = 2821373153748262800L ;

	@SearchableProperty (name = "time", format = DateTools.GLOBAL_DATE_FORMAT)
	private Date time ;

	@SearchableProperty (name = "userId")
	private long userId ;

	/**
	 * @param memberId id of the member who logged in.
	 * @param loginTime time in which the member logged in.
	 */
	public Login(final long memberId, final Date loginTime)
	{
		this.time = loginTime ;
		this.userId = memberId ;
	}

	// for serialization
	@SuppressWarnings("unused")
	private Login()
	{
		// empty
	}

	/**
	 * @return time in which the member logged in.
	 */
	public Date getTime()
	{
		return this.time ;
	}
	/**
	 * @return id of the user which logged in.
	 */
	public long getUserId()
	{
		return this.userId ;
	}

	/**
	 * @see persistence.Persistent#toString()
	 */
	@Override
	public String toString()
	{
		return this.getUserId() + " at " + this.getTime() ;
	}

	@SuppressWarnings("unused")
	private void setTime(final Date time)
	{
		this.time = time ;
	}

	@SuppressWarnings("unused")
	private void setUserId(final long user)
	{
		this.userId = user ;
	}
}
